<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            background-color: green;
            /* padding: 25% 0; */
            /* 前提 宽度是viewport */
            /* height: 50vw; */
        }
    </style>
</head>
<body>
    <div class="box">

    </div>
    <script>
        const oBox=document.querySelector('.box');
        window.onload=function(){
            oBox.style.height=(oBox.offsetWidth/2)+'px'; // 会重绘影响性能
            // ？发散思维 
        }
        window.onresize=function(){
            oBox.style.height=(oBox.offsetWidth/2)+'px';
        }
    </script>
</body>
</html>